package com.leapp.sk.viewdelegate.adapter.im

import android.content.Context
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.mvp.view.GlideCircleTransform
import com.example.mvp.view.LKCircleImageView
import com.leapp.sk.R
import com.example.mvp.bean.ClassMemberInfoEntity

/**
 * 未读消息适配器视图托管
 * @author  chaohaipeng  on 2018/7/30.
 */
class UnReadMessageAdapterDelegate : BaseAdapterDelegate() {

    /**
     * 头像加载操作
     */
    var mHeadRequestOptions: RequestOptions = RequestOptions()
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.adapter_read_message_state
    }

    fun setData(context: Context, data: ClassMemberInfoEntity){
        val ima_arms_avatar = getView<LKCircleImageView>(R.id.ima_arms_avatar)
        val tv_arms_nick = getView<TextView>(R.id.tv_arms_nick)
        tv_arms_nick.text=data.nickName
        setHead(context,data.avatar,ima_arms_avatar)

    }
    /**
     * 设置头像和昵称
     */
    private  fun setHead(context: Context, headUrl:String?, headImage: LKCircleImageView){
        val tag = headImage.getTag(R.id.tag_head)
        if ( tag==null||!tag?.equals(headUrl)){
            val mRequestManager = Glide.with(context)
            mHeadRequestOptions?.diskCacheStrategy(DiskCacheStrategy.NONE)
            mHeadRequestOptions?.skipMemoryCache(true)
            mHeadRequestOptions?.error(R.mipmap.icon_defout_head)
            mHeadRequestOptions?.transforms(GlideCircleTransform(context))
            mRequestManager?.load(headUrl)
                    ?.thumbnail(0.2f)
                    ?.apply(mHeadRequestOptions)
                    ?.into(headImage)
            headImage.setTag(R.id.tag_head,headUrl)
        }
    }
}